package com.sxkj.web.controller.pay;

import com.github.wxpay.sdk.WXPayConstants;
import com.sxkj.common.pay.wxpay.WXPay;
import com.sxkj.common.response.ResponseResult;
import com.sxkj.service.pay.WxPayService;
import com.sxkj.service.wechat.WechatUserService;
import com.sxkj.web.config.WxPayConfig;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Zhang Xingliang
 *
 * @description: 微信用户
 * @date 2019-12-25 09:39:56
 */
@RestController
@RequestMapping("/pay/wxpay")
public class WxPayController {

	@Autowired
	private WechatUserService wechatUserService;

	@Autowired
	private WxPayService wxPayService;

	@Autowired
	private WxPayConfig wxPayConfig;

	@ApiOperation(value = "查询微信用户列表")
	@RequestMapping(value = "/pay")
	public ResponseResult wxPay(@RequestBody Map<String, String> requestData) {
		try {
			WXPay wxpay = new WXPay(wxPayConfig,true);
			Map<String, String> data = new HashMap<>();
			data.put("mch_billno", "sxkj" + System.currentTimeMillis());
			data.put("send_name", wxPayConfig.getSendName());
			data.put("scene_id", "PRODUCT_1");
			data.put("re_openid", "o3jef0cZK5ThapWaw3YLVJG7_ovU");
			data.put("total_amount", String.valueOf(10));
			data.put("total_num", "1");
			Map<String, String> resp = wxPayService.sendRedPack(data);
			//发送成功
			if(resp.get("return_code").equals(WXPayConstants.SUCCESS) && resp.get("result_code").equals(WXPayConstants.SUCCESS)){

			}else{

			}

			// 返回状态码
			String return_code = resp.get("return_code");
			// 返回信息
			String return_msg = resp.get("return_msg");
			// 业务结果
			String result_code = resp.get("result_code");
			// 错误代码
			String err_code = resp.get("err_code");
			// 错误代码描述
			String err_code_des = resp.get("err_code_des");
			return ResponseResult.success();
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

}
